import axios from 'axios'
import Vue from 'vue'
import Vuex from 'vuex'
import goods from './newlist/goods.js'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    count: 100,
    bookList:[]
  },
  mutations:{
   initBooks(state,newBooks){
     state.bookList = newBooks
   }
  },
  getters:{
    getSum:state =>{
      return state.bookList.reduce((sum,item)=>sum+item.price,0)
    }
  },
  actions:{
   async getTiong(context){
   const res =  await axios.get('http://www.liulongbin.top:3009/api/getbooks')
      context.commit('initBooks',res.data.data)

    }
  },
  modules:{
    goods,
  }
})
export default store